var app = getApp()
Page({
  data: {
    title: '',
    conf_data:[],
    hairdresser_time:[],
   
    is_toggle_today:1,
    toggle_today_hove_class:"day",
     toggle_today_class:"font_day",
      toggle_tomorrow_hove_class:"font_day",
     toggle_tomorrow_class:"day",
     today_time:[],
    tomorrow_time:[],
    cell_id:0,
    hairdresserInfo:[],
    serverItem:[],
    order_time:0,
    iphone:'',
    sex:2

  },



  onLoad: function (e) {
    
    var that = this
 
    wx.request({
      url: app.globalData.api_url + "index.php?ac=mfapi&ts=setting_all",
      data: {},
      method:"GET",
      header: { 'content-type': 'application/json' },
      success: function (res) {
      
       that.setData({
        conf_data:res.data

       });
      }
    });
    //获取配置信息
    
      wx.request({       
        url: app.globalData.api_url + "index.php?ac=mfapi&ts=get_hairdresser_order",
        data: { hairdresser_id:e.hairdresser_id,item_id:e.itemId},
        method:"POST",
        header: { 'content-type': 'application/json' },
        success:function(res){
          
         
          that.setData({
            hairdresser_time: res.data,
            today_time:res.data.today_time,

            tomorrow_time:res.data.tomorrow_time,
            hairdresserInfo:res.data.hairdresser,
            serverItem:res.data.server_item

          });
          console.log(res.data);
          wx.setStorage({
              key:"tomorrow_time",
              data:res.data.tomorrow_time
            });
          wx.setStorage({
              key:"today_time",
              data:res.data.today_time
            });
          
        }
      });
      //获取订单信息



      

  },
  confirm_iphone:function(e){
    var that = this;
    that.setData({
      iphone: e.detail.value
    });
  },
  toggle_today:function(e){
     var that = this;

        that.setData({
        toggle_today_class:"font_day",
        is_toggle_today:1,
        toggle_today_hove_class:"day",
        toggle_tomorrow_hove_class:"font_day",
        toggle_tomorrow_class:"day",
        cell_id:0
        

       });
        wx.getStorage({
            key: 'today_time',
            success: function(res) {

                that.setData({
               today_time:res.data
                  });
                
            } 
          });



    
  },
  radioChange:function(e){
    var that = this;
    
    that.setData({
      sex: e.detail.value
    });
  },
  toggle_tomorrow:function(e){
     var that = this;
        that.setData({
        toggle_today_class:"day",
        is_toggle_today:0,
        toggle_today_hove_class:"font_day",
        toggle_tomorrow_hove_class:"day",
        toggle_tomorrow_class:"font_day",
        cell_id:0

       });
        wx.getStorage({
            key: 'tomorrow_time',
            success: function(res) {

                that.setData({
               today_time:res.data
                  });
                console.log(res.data);
            } 
          });
       
    
  },
  on_time:function(e){
    console.log(wx.getStorageSync("_hairdresser_id"));
      var that = this;
      that.setData({
        cell_id:e.target.dataset.idx,
        order_time:e.target.dataset.s_time
      });

  },
  createOrder:function(e){
    var member_id = wx.getStorageSync("_hairdresser_id");
    if(e.target.dataset.order_time==0)
    {
      wx.vibrateShort();
      wx.showToast({
        title:"未选择时间",
        icon:"loading",
        duration:2000

      });return;
    }
    if (!e.target.dataset.iphone || e.target.dataset.iphone.length<11) {
      wx.vibrateShort();
      wx.showToast({
        title: "手机号必填",
        icon: "loading",
        duration: 2000

      }); return;
    }
     console.log(e);
     wx.request({
       url: app.globalData.api_url + "index.php?ac=mfapi&ts=orders_add",
       data: { 
         hairdresser_id: e.target.dataset.hairdresser_id,
         item_id: e.target.dataset.itemid,
         member_id: member_id,
         order_name: e.target.dataset.order_name,
         order_price: e.target.dataset.order_price,
         order_time: e.target.dataset.order_time,
         server_time: e.target.dataset.server_time,
         iphone:e.target.dataset.iphone,
         sex:e.target.dataset.sex
          },
       method: "POST",
       header: { 'content-type': 'application/json' },
       success:function(rs){
         if (rs.data.result==1){
           wx.showModal({
             title: '交易状态',
             content:"下单成功",
             showCancel:false,
             confirmText:"在线支付",
             confirmColor:"#3CC51F",
             success:function(){
               wx.redirectTo({
                 url:"/pages/business/business"
               });
             }
           })
         }
       }
     })
    }
  
})